﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using CustomerList.Model;
using GalaSoft.MvvmLight.Threading;

namespace MyMeetup.Helpers
{
    public class CheckinHelper
    {
        private INavigationService _navigationService;
        private DataService _dataService;
        public CheckinHelper(DataService dataService, INavigationService navigationService)
        {
            _dataService = dataService;
            _navigationService = navigationService;
            DispatcherHelper.Initialize();
        }

        public void CheckinToEvent(string eventId)
        {
            if (LicenseHelper.IsTrial())
            {
                _navigationService.NavigateTo(new Uri("/BuyNow.xaml", UriKind.Relative));
                return;
            }

            _dataService.Checkin(eventId, CheckinCallback, ResponseHelper.ErrorCallback);
        }

        private void CheckinCallback(Checkin checkin)
        {
            string msg = checkin.problem == null ? "You have successfully checked in to this meetup!" : "Could not check in to this meetup.";
            DispatcherHelper.CheckBeginInvokeOnUI(() => MessageBox.Show(msg));
        }

    }
}
